﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using 聚欣订单分析.PublicClass;

namespace 聚欣订单分析
{
    public partial class DataAdd : System.Web.UI.Page
    {
        PLSQLClass PL = new PLSQLClass();
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "订单录入";
            if (!IsPostBack)
            {
                seYear.Value = DateTime.Now.Year;
            }
        }

        /// <summary>
        /// 自动生成订单号
        /// </summary>
        private void AutoDdNo()
        {
            string strDDH = ddqz.Text + seYear.Value + "S-1";
            string strSql = "select TOP 1 订单号 from tbl_DDB where 订单号 like '%" + ddqz.Text +  seYear.Value + "S%' ORDER BY ID DESC";
            DataTable dt = PL.SqlBind(strSql);
            if (dt.Rows.Count > 0)
            {
                strDDH = ddqz.Text + seYear.Value + "S-" + (Convert.ToInt32(dt.Rows[0][0].ToString().Split('-')[1]) + 1).ToString();
            }
           
            txtDDH.Text = strDDH;
        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            AutoDdNo();
        }

        protected void btnSh_Click(object sender, EventArgs e)
        {
            string strSQL = "INSERT into tbl_DDB(年份,订单号,省,地市,运营商,项目,类型,[有无订单合同],[订单日期],[订单金额],[尾款],付款方式,[报账联系人],[责任人],[备注],[维保时间])VALUES('" + seYear.Value.ToString() + "','" + txtDDH.Text.Trim() + "','" + txtProvince.Text.Trim() + "','" + txtCity.Text.Trim() + "','" + txtYys.Text.Trim() + "','" + txtProjectName.Text.Trim() + "','" + txtType.Text.Trim() + "','" + cbHT.Text + "','" + deDd.Date.ToString() + "','" + seDdje.Text + "','" + seDdje.Text + "','" + txtFkfs.Text.Trim() + "','" + txtBzlxr.Text.Trim() + "','" + txtZrr.Text.Trim() + "','" + txtBz.Text.Trim() + "','" + deDd.Date.AddYears(3).ToString() + "')";
            if (PL.SqlGetData(strSQL) >= 1)
            {
                JsHelper.AlertAndRedirect("添加成功！", "DataAdd.aspx");
            }
            else
                JsHelper.Alert("添加失败,请联系管理员！");
        }
    }
}
